package com.xm;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

/**
 * @Author：xm
 * @Project：runoob
 * @Date：2024/7/22 1:44
 */

public class Callable10 implements Callable<Integer> {
    public static void main(String[] args) {
        Callable10 callable10 = new Callable10();
        FutureTask<Integer> future = new FutureTask<>(callable10);
        for (int i = 0; i < 100; i++) {
            System.out.println(Thread.currentThread().getName() + " 的循环变量i的值为" + i);
            if (i == 6) {
                new Thread(future,"有返回值的线程").start();
            }
        }
        try {
            System.out.println("子线程的返回值："+future.get());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public Integer call() throws Exception {
        int i = 0;
        for (; i < 100; i++) {
            System.out.println(Thread.currentThread().getName() + " " + i);
        }
        return i;
    }
}
